package ca.liu.scaffoldingmvctest.service;

import ca.liu.scaffoldingmvctest.domain.StLog;
import ca.liu.scaffoldingmvctest.domain.StUser;

import java.util.List;
import java.util.Set;

import org.junit.Test;

import org.junit.runner.RunWith;

import org.springframework.beans.factory.annotation.Autowired;

import org.springframework.beans.factory.support.DefaultListableBeanFactory;

import org.springframework.context.ApplicationContext;

import org.springframework.mock.web.MockHttpServletRequest;

import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.TestExecutionListeners;

import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;

import org.springframework.test.context.support.DependencyInjectionTestExecutionListener;
import org.springframework.test.context.support.DirtiesContextTestExecutionListener;

import org.springframework.test.context.transaction.TransactionalTestExecutionListener;

import org.springframework.transaction.annotation.Transactional;

import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.RequestScope;
import org.springframework.web.context.request.ServletRequestAttributes;
import org.springframework.web.context.request.SessionScope;

/**
 * Class to run the service as a JUnit test. Each operation in the service is a separate test.
 *
 */

@RunWith(SpringJUnit4ClassRunner.class)
@TestExecutionListeners({
		DependencyInjectionTestExecutionListener.class,
		DirtiesContextTestExecutionListener.class,
		TransactionalTestExecutionListener.class })
@ContextConfiguration(locations = {
		"file:./src/main/resources/scaffoldingmvctest-security-context.xml",
		"file:./src/main/resources/scaffoldingmvctest-service-context.xml",
		"file:./src/main/resources/scaffoldingmvctest-dao-context.xml",
		"file:./src/main/resources/scaffoldingmvctest-web-context.xml" })
@Transactional
public class StLogServiceTest {

	/**
	 * The Spring application context.
	 *
	 */
	@SuppressWarnings("unused")
	private ApplicationContext context;

	/**
	 * The service being tested, injected by Spring.
	 *
	 */
	@Autowired
	protected StLogService service;

	/**
	 * Instantiates a new StLogServiceTest.
	 *
	 */
	public StLogServiceTest() {
		setupRequestContext();
	}

	/**
	 * Operation Unit Test
	 * Return a count of all StLog entity
	 * 
	 */
	@Test
	public void countStLogs() {
		Integer response = null;
		response = service.countStLogs();
		// TODO: JUnit - Add assertions to test outputs of operation: countStLogs
	}

	/**
	 * Operation Unit Test
	 * Save an existing StUser entity
	 * 
	 */
	@Test
	public void saveStLogStUser() {
		// TODO: JUnit - Populate test inputs for operation: saveStLogStUser 
		Integer id = 0;
		StUser related_stuser = new ca.liu.scaffoldingmvctest.domain.StUser();
		StLog response = null;
		response = service.saveStLogStUser(id, related_stuser);
		// TODO: JUnit - Add assertions to test outputs of operation: saveStLogStUser
	}

	/**
	 * Operation Unit Test
	 * Load an existing StLog entity
	 * 
	 */
	@Test
	public void loadStLogs() {
		Set<StLog> response = null;
		response = service.loadStLogs();
		// TODO: JUnit - Add assertions to test outputs of operation: loadStLogs
	}

	/**
	 * Operation Unit Test
	 * Delete an existing StLog entity
	 * 
	 */
	@Test
	public void deleteStLog() {
		// TODO: JUnit - Populate test inputs for operation: deleteStLog 
		StLog stlog = new ca.liu.scaffoldingmvctest.domain.StLog();
		service.deleteStLog(stlog);
	}

	/**
	 * Operation Unit Test
	 * Return all StLog entity
	 * 
	 */
	@Test
	public void findAllStLogs() {
		// TODO: JUnit - Populate test inputs for operation: findAllStLogs 
		Integer startResult = 0;
		Integer maxRows = 0;
		List<StLog> response = null;
		response = service.findAllStLogs(startResult, maxRows);
		// TODO: JUnit - Add assertions to test outputs of operation: findAllStLogs
	}

	/**
	 * Operation Unit Test
	 */
	@Test
	public void findStLogByPrimaryKey() {
		// TODO: JUnit - Populate test inputs for operation: findStLogByPrimaryKey 
		Integer id_1 = 0;
		StLog response = null;
		response = service.findStLogByPrimaryKey(id_1);
		// TODO: JUnit - Add assertions to test outputs of operation: findStLogByPrimaryKey
	}

	/**
	 * Operation Unit Test
	 * Save an existing StLog entity
	 * 
	 */
	@Test
	public void saveStLog() {
		// TODO: JUnit - Populate test inputs for operation: saveStLog 
		StLog stlog_1 = new ca.liu.scaffoldingmvctest.domain.StLog();
		service.saveStLog(stlog_1);
	}

	/**
	 * Operation Unit Test
	 * Delete an existing StUser entity
	 * 
	 */
	@Test
	public void deleteStLogStUser() {
		// TODO: JUnit - Populate test inputs for operation: deleteStLogStUser 
		Integer stlog_id = 0;
		Integer related_stuser_id = 0;
		StLog response = null;
		response = service.deleteStLogStUser(stlog_id, related_stuser_id);
		// TODO: JUnit - Add assertions to test outputs of operation: deleteStLogStUser
	}

	/**
	 * Autowired to set the Spring application context.
	 *
	 */
	@Autowired
	public void setContext(ApplicationContext context) {
		this.context = context;
		((DefaultListableBeanFactory) context.getAutowireCapableBeanFactory()).registerScope("session", new SessionScope());
		((DefaultListableBeanFactory) context.getAutowireCapableBeanFactory()).registerScope("request", new RequestScope());
	}

	/**
	 * Sets Up the Request context
	 *
	 */
	private void setupRequestContext() {
		MockHttpServletRequest request = new MockHttpServletRequest();
		ServletRequestAttributes attributes = new ServletRequestAttributes(request);
		RequestContextHolder.setRequestAttributes(attributes);
	}
}
